<template>
  <div>
    <el-breadcrumb separator="/" style="padding-left:10px;padding-bottom:10px;font-size:12px;">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{ this.$router.currentRoute.name }}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-page-header @back="goBack"
                      :content="this.$router.currentRoute.name.substring(this.$router.currentRoute.name.indexOf('/')+1)">
      </el-page-header>
      <el-container style="margin-top: 3vh">
        <el-header>
          <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <el-menu-item index="0">客户回收站</el-menu-item>
            <el-menu-item index="1">资源回收站</el-menu-item>
          </el-menu>
        </el-header>
        <el-main id="showMain">
          <div v-show="isShows[0].isShow">
            <!-- 系统通知列表卡片区 -->
            <el-form :inline="true" ref="form" size="small" style="margin-top: -1vh">
              <el-row>
                <h4 style="margin: 1vh 0 2vh;color: #1f2d3d">条件查询区</h4>
              </el-row>
              <el-form-item>
                <el-input
                    style="width: 160px;"
                    clearable
                    placeholder="请输入任务包名称"
                    v-model="queryMap_high.taskPackageName"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style="width: 140px;"
                    clearable
                    placeholder="请输入客户名称"
                    v-model="queryMap_high.resourceName"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style="width: 150px;"
                    clearable
                    placeholder="请输入联系人名称"
                    v-model="queryMap_high.linkman"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style="width: 130px;"
                    clearable
                    placeholder="请输入电话"
                    v-model="queryMap_high.phoneA"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-select
                    style="width: 140px;"
                    placeholder="请选择账号"
                    v-model="queryMap_high.accountName"
                    @change="getUserName1"
                    filterable
                >
                  <el-option
                      v-for="(name) in accountName"
                      :key="name"
                      :label="name"
                      :value="name">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 120px;"
                    placeholder="请选择标签"
                    v-model="queryMap_high.labelId"
                >
                  <el-option
                      v-for="(labelInfo) in labelInfoList"
                      :key="labelInfo.labelId"
                      :label="labelInfo.options"
                      :value="labelInfo.labelId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="请选择行业类别"
                    v-model="queryMap_high.industryId"
                >
                  <el-option
                      v-for="(industry) in industryList"
                      :key="industry.industryId"
                      :label="industry.options"
                      :value="industry.industryId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="请选择客户种类"
                    v-model="queryMap_high.clientTypeId"
                >
                  <el-option
                      v-for="(clientType) in clientTypeList"
                      :key="clientType.clientTypeId"
                      :label="clientType.options"
                      :value="clientType.clientTypeId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="客户来源"
                    v-model="queryMap_high.sourceId"
                >
                  <el-option
                      v-for="(source) in sourceList"
                      :key="source.sourceId"
                      :label="source.options"
                      :value="source.sourceId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="时间筛选:">
                <el-select
                    clearable
                    style="width: 120px;"
                    placeholder="请选择时间"
                    v-model="queryMap_high.time"
                >
                  <el-option label="创建时间" value="1"></el-option>
                  <el-option label="呼叫时间" value="2"></el-option>
                  <el-option label="删除时间" value="3"></el-option>
                </el-select>
                <el-date-picker
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions"
                    @change="handleDateChange"
                    v-model="time">
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button @click="reset(0)" icon="el-icon-refresh">重置</el-button>
                <el-button type="primary" icon="el-icon-search" @click="searchDeleteCustomerList">查询</el-button>
              </el-form-item>
            </el-form>

            <div style="margin-bottom: 10px;display: flex">
              <span class="hint" style="flex: 1;"></span>
              <el-button icon="el-icon-delete" v-hasPermission="'customer:erase'" @click="customerDeletes">清空回收站</el-button>
              <el-button icon="el-icon-refresh" v-hasPermission="'customer:restore'" @click="updateIsDeleteList">批量恢复</el-button>
              <el-button icon="el-icon-right" v-hasPermission="'customer:assign'" @click="distribute">批量分配</el-button>

              <el-button icon="el-icon-delete" v-hasPermission="'customer:delete'" @click="delCustomerList">批量删除</el-button>
            </div>

            <!-- 表格区域 -->
            <el-table ref="multipleTable" :data="deleteCustomer" size="small" @selection-change="handleSelectionChange"
                      border style="width: 100%;" height="420">
              <el-table-column type="selection" width="40"></el-table-column>
              <el-table-column prop="accountName" label="账户" width="100" fixed="left"></el-table-column>
              <el-table-column prop="taskPackageName" label="任务名称" width="100"></el-table-column>
              <el-table-column prop="resourceName" label="客户名称" width="100"></el-table-column>
              <el-table-column prop="linkman" label="联系人" width="100"></el-table-column>
              <el-table-column prop="phoneA" label="电话A" width="100"></el-table-column>
              <el-table-column prop="phoneB" label="电话B" width="100"></el-table-column>

              <el-table-column prop="userName" label="所属人" width="100"></el-table-column>
              <el-table-column prop="lastCallTime" label="最后呼叫时间" width="100"></el-table-column>
              <el-table-column prop="sourceOptions" label="客户来源" width="100"></el-table-column>
              <el-table-column prop="remark" label="备注" width="100"></el-table-column>
              <el-table-column prop="clientTypeOptions" label="客户种类" width="100"></el-table-column>
              <el-table-column prop="industryOptions" label="行业类型" width="100"></el-table-column>
<!--              <el-table-column prop="test" label="生命周期" width="100"></el-table-column>-->
              <el-table-column prop="followContent" label="跟进内容" width="100"></el-table-column>
<!--              <el-table-column prop="test" label="创建时间" width="100"></el-table-column>-->
<!--              <el-table-column prop="test" label="更新时间" width="100"></el-table-column>-->
              <el-table-column prop="deleteTime" label="删除时间" width="100"></el-table-column>
              <el-table-column prop="test" label="操作" fixed="right" width="130">
                <template v-slot="scope">
                  <el-tooltip content="恢复"  placement="top" effect="light">
                    <el-button type="success" size="mini" v-hasPermission="'customer:restore'"  icon="el-icon-refresh" @click="updateIsDelete(scope.row.resourceId)"  plain circle></el-button>
                  </el-tooltip>
                  <el-tooltip content="分配客户" placement="top" effect="light">
                    <el-button type="primary" v-hasPermission="'customer:assign'" @click="distribute2(scope.row.resourceId)" icon="el-icon-right" plain
                               circle></el-button>
                  </el-tooltip>
                  <el-tooltip content="彻底删除" placement="top" effect="light">
                    <el-button type="danger" icon="el-icon-delete" v-hasPermission="'customer:delete'"  @click="delCustomer(scope.row.resourceId)" plain circle></el-button>
                  </el-tooltip>
                </template>
              </el-table-column>
            </el-table>

            <!-- 分页-公海 -->
            <el-pagination
                style="margin-top:10px;"
                background
                @size-change="handleSizeChange_high"
                @current-change="handleCurrentChange_high"
                :current-page="queryMap_high.pageNum"
                :page-sizes="this.$globalVar.sizes"
                :page-size="queryMap_high.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalCustomer"
            ></el-pagination>
          </div>
          <div v-show="isShows[1].isShow">

            <!-- 系统通知列表卡片区 -->
            <el-form :inline="true" ref="form" size="small" style="margin-top: -1vh">
              <el-row>
                <h4 style="margin: 1vh 0 2vh;color: #1f2d3d">条件查询区</h4>
              </el-row>
              <el-form-item>
                <el-input
                    style="width: 160px;"
                    clearable
                    placeholder="请输入任务包名称"
                    v-model="queryMap_recycle.taskPackageName"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style=" width: 140px;"
                    clearable
                    placeholder="请输入客户名称"
                    v-model="queryMap_recycle.resourceName"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style="width: 150px;"
                    clearable
                    placeholder="请输入联系人名称"
                    v-model="queryMap_recycle.linkman"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                    style="width: 130px;"
                    clearable
                    placeholder="请输入电话"
                    v-model="queryMap_recycle.phoneA"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-select
                    style="width: 140px;"
                    placeholder="请选择账号"
                    v-model="queryMap_recycle.accountName"
                    @change="getUserName2"
                    filterable
                >
                  <el-option
                      v-for="(name) in accountName"
                      :key="name"
                      :label="name"
                      :value="name">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="请选择行业类别"
                    v-model="queryMap_recycle.industryId"
                >
                  <el-option label="全部" value=" "></el-option>
                  <el-option
                      v-for="(industry) in industryList"
                      :key="industry.industryId"
                      :label="industry.options"
                      :value="industry.industryId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select v-model="queryMap_recycle.userId" style="width: 200px;" clearable filterable
                           placeholder="请选择创建人">
                  <el-option
                      v-for="(user) in userList"
                      :key="user.userId"
                      :label="user.userName+'('+user.nickName+')'"
                      :value="user.userId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="是否存在"
                    v-model="queryMap_recycle.isExists"
                >
                  <el-option label="否" value="0"></el-option>
                  <el-option label="是" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="请选择标签资源"
                    v-model="queryMap_recycle.resourceTag"
                >
                  <el-option label="未标记" value="0"></el-option>
                  <el-option label="无效" value="1"></el-option>
                  <el-option label="待定" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                    clearable
                    style="width: 140px;"
                    placeholder="请选择是否呼叫"
                    v-model="queryMap_recycle.isCall"
                >
                  <el-option label="否" value="0"></el-option>
                  <el-option label="是" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="时间筛选:">
                <el-select
                    clearable
                    style="width: 120px;"
                    placeholder="请选择时间"
                    v-model="queryMap_recycle.time"
                >
                  <el-option label="创建时间" value="1"></el-option>
                  <el-option label="删除时间" value="3"></el-option>
                </el-select>
                <el-date-picker
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions"
                    @change="handleDateChange"
                    v-model="time">
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button @click="reset(1)" icon="el-icon-refresh">重置</el-button>
                <el-button type="primary" icon="el-icon-search" @click="searchDeleteZiYuanList">查询</el-button>
              </el-form-item>
            </el-form>
            <div style="margin-bottom: 10px;display: flex">
              <span class="hint" style="flex: 1;"></span>

              <el-button icon="el-icon-refresh" v-hasPermission="'customer:erase'" @click="updateIsDeleteZiYuanListList">批量恢复</el-button>
              <el-button icon="el-icon-delete" v-hasPermission="'resource:restore'" @click="resourceInfoDeletes">清空回收站</el-button>
<!--              <el-button icon="el-icon-download"  v-hasPermission="'resource:export'" @click="resourceInfoExcel">导出</el-button>-->
            </div>
            <!-- 表格区域 -->
            <el-table ref="multipleTable" :data="deleteZiYuanList" size="small" @selection-change="handleSelectionChange"
                      border style="width: 100%;" height="420">
              <el-table-column type="selection" width="40"></el-table-column>
              <el-table-column prop="accountName" label="账户" width="100" fixed="left"></el-table-column>
              <el-table-column prop="taskPackageName" label="任务名称" width="100"></el-table-column>
              <el-table-column prop="resourceName" label="客户名称" width="100"></el-table-column>
              <el-table-column prop="phoneA" label="电话A" width="100"></el-table-column>
              <el-table-column prop="phoneB" label="电话B" width="100"></el-table-column>
              <el-table-column prop="test" label="是否呼叫" width="100"><template v-slot="scope"><span>{{showCall(scope.row)}}</span></template></el-table-column>
              <el-table-column prop="test" label="资源标签" width="100"><template v-slot="scope"><span>{{showTag(scope.row)}}</span></template></el-table-column>
              <el-table-column prop="userName" label="归属人" width="100"></el-table-column>
              <el-table-column prop="createTime" label="创建时间" width="100"></el-table-column>
              <el-table-column prop="linkman" label="联系人姓名" width="100"></el-table-column>
              <el-table-column prop="test" label="是否存在" width="100"><template v-slot="scope"><span>{{showExists(scope.row)}}</span></template></el-table-column>
              <el-table-column prop="industryOptions" label="行业类型" width="100"></el-table-column>
              <el-table-column prop="deleteTime" label="删除时间" width="100"></el-table-column>
              <el-table-column prop="remark" label="备注" width="100"></el-table-column>
            </el-table>

            <!-- 分页 -->
            <el-pagination
                style="margin-top:10px;"
                background
                @size-change="handleSizeChange_recycle"
                @current-change="handleCurrentChange_recycle"
                :current-page="queryMap_recycle.pageNum"
                :page-sizes="this.$globalVar.sizes"
                :page-size="queryMap_recycle.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalZiYuanList"
            ></el-pagination>
          </div>
        </el-main>
      </el-container>
      <!-- 选择用户窗口 -->
      <ElectUsersBox title="分配客户" @confirmUserId="confirmResourcesId" :isShow="electUsersBoxShow" @updateElectUsersBoxShow="electUsersBoxShow=false"/>
    </el-card>
  </div>
</template>
<script>
import ElectUsersBox from "@/components/electUsersBox.vue";
import axios from "axios";

export default {
  data() {
    // 计算最近一周的起始和结束日期
    const end = new Date();
    const start = new Date();
    end.setTime(end.getTime() + 3600 * 1000 * 24 * 1); // 当前时间减去 7 天
    return {
      multipleSelection: [],
      activeIndex: '0',//初始显示菜单下标
      totalCustomer:0,
      totalZiYuanList: 0,
      time: [start,end],//起始时间和截止时间
      accountName:[],//账号
      userList: [],//归属人信息
      //clientStatusList:[],//客户状态信息
      clientTypeList: [],//客户类型
      sourceList: [],//来源信息
      industryList: [],//行业类型
      deleteZiYuanList:[],//资源列表
      labelInfoList:[],//标签列表
      id:[],//分配客户的id
      batchAllocationMap:{},
      deleteCustomer:[],//客户列表信息
      electUsersBoxShow: false,
      isShows: [
        {isShow: true},
        {isShow: false}
      ],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      //查询对象-客户
      queryMap_high: {
        pageNum: 1,
        pageSize: 10,
        resourceName: "",//客户名称
        linkman:"",//联系人名称
        phoneA:"",
        labelId:"",
        industryId:"",
        clientTypeId: "",
        sourceId: "",
        time:'1',
        startTime: "",
        endTime: "",
        accountName:'',
        taskPackageName:"",
      },
      //查询对象-资源
      queryMap_recycle: {
        pageNum: 1,
        pageSize: 10,
        resourceName: "",//客户名称
        linkman:"",//联系人名称
        phoneA:"",
        industryId:"",
        userId: "",
        isExists:"",
        taskPackageName:"",
        resourceTag:"",
        isCall:"",
        time:'1',
        startTime: "",
        endTime: "",
        accountName:'',
      },
    }
  },
  methods: {

    /**
     * 全选功能
     *
     */
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * 头部状态栏点击事件
     * @param key 点击的下标
     */
    handleSelect(key) {
      for (let i = 0; i < this.isShows.length; i++) {
        this.isShows[i].isShow=false;
      }
      this.activeIndex=key
      this.test(key)
      this.isShows[key].isShow=true;
    },
    /**
     * 填充表格
     * @param key
     */
    test(key){
      this.reset(key)
      if (key==0){
        //调用查询
        this.getDeleteCustomerList();
        this.getClientType();
        this.getSource();
        this.getIndustry();
      }else if(key==1){
        this.getDeleteZiYuanList();
        this.getUserName();
        this.getIndustry();
      }
    },
    /**
     * 重置
     */
    reset(key) {
      // 计算最近一周的起始和结束日期
      const end = new Date();
      const start = new Date();
      end.setTime(end.getTime() + 3600 * 1000 * 24 * 1); // 当前时间减去 7 天
      this.multipleSelection=[]
      this.time = [start,end]
      if (key === 1) {
        this.queryMap_recycle = {
          pageNum: 1,
          pageSize: 10,
          resourceName: "",//客户名称
          linkman:"",//联系人名称
          phoneA:"",
          industryId:"",
          userId: "",
          isExists:"",
          taskPackageName:"",
          resourceTag:"",
          isCall:"",
          time:'1',
          startTime: "",
          endTime: "",
          accountName:'',
        }
      } else {
        this.queryMap_high = {
          pageNum: 1,
          pageSize: 10,
          nickName: "",
          clientTypeId: "",
          sourceId: "",
          phone: "",
          agentStatus: "",
          NumberVerifStatus: "",
          isMove: "",
          deptId: "",
          time:'1',
          startTime: "",
          endTime: "",
          accountName:'',
          taskPackageName:"",
        }
      }
      this.getClientType();
      this.getSource();
      this.getIndustry();
      this.getLabelInfo();
    },
    /**
     *  改变页码-客户
     */
    handleSizeChange_high(newSize) {
      this.queryMap_high.pageSize = newSize;
      this.getDeleteCustomerList();
    },
    /**
     * 翻页-客户
     */
    handleCurrentChange_high(current) {
      this.queryMap_high.pageNum = current;
      this.getDeleteCustomerList();
    },
    /**
     *  改变页码-资源
     */
    handleSizeChange_recycle(newSize) {
      this.queryMap_recycle.pageSize = newSize;
      this.getDeleteZiYuanList();
    },
    /**
     * 翻页-资源
     */
    handleCurrentChange_recycle(current) {
      this.queryMap_recycle.pageNum = current;
      this.getDeleteZiYuanList();
    },

    searchDeleteCustomerList(){
      this.queryMap_high.pageNum = 1;
      this.getDeleteCustomerList();
    },

    /**
     * 加载进入回收站的客户列表
     */
    async getDeleteCustomerList() {
      const { data: res } = await this.$http.get("/resourceInfo/IsDeleteCustomerList", {
        params: this.queryMap_high
      });
      if(!res.success){
        return this.$message.error("获取进入回收站的资源列表失败:"+res.data.errorMsg);
      }
      this.totalCustomer = res.data.total;
      this.deleteCustomer = res.data.rows;
      this.multipleSelection=[]
    },
    /**
     * 根据条件清空进入回收站的客户
     */
    async customerDeletes(){
      if (this.totalCustomer>0){//判断是否有信息
        const res = await this.$confirm(
            "此操作将会把查询出的所有进入回收站的客户删除, 是否继续?",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }
        ).catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
        if (res === "confirm") {
          const { data: res } = await this.$http.post("/resourceInfo/deletesByCustomer",this.queryMap_high);
          console.log(res);
          if(res.success){
            this.$notify.success({
              title:'操作成功',
              message:"查询出所有的信息已成功删除",
            });
            await this.getDeleteCustomerList();
          }else {
            this.$message.error(res.data.errorMsg);
          }
        }
      }else {
        this.$message({
          title:'操作失败',
          message:"没有任何数据可清空",
        });
      }
    },
    /**
     * 批量删除回收站的客户
     */
    delCustomerList(){
      const ids = this.multipleSelection.map(row => row.resourceId);
      if (ids.length>0) {
        this.delCustomer(ids)
      }else {
        this.$message({
          title:'操作失败',
          message:"未选中客户",
        });
      }
    },
    /**
     * 删除回收站的客户
     */
    async delCustomer(id) {
      const res = await this.$confirm(
          id.length>1?"此操作将会把选中的客户删除, 是否继续?":"此操作将会把此客户删除, 是否继续?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
      ).catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除"
        });
      });
      if (res === "confirm") {
        const { data: res } = await this.$http.delete("/resourceInfo/deleteCustomer/" + id);
        console.log(res);
        if(res.success){
          this.$notify.success({
            title:'操作成功',
            message:id.length>1?"选中的客户已成功删除":"此客户成功删除",
          });
          await this.getDeleteCustomerList();
        }else {
          this.$message.error(res.data.errorMsg);
        }
      }
    },
    /**
     * 批量恢复
     */
    updateIsDeleteList(){
      const ids = this.multipleSelection.map(row => row.resourceId);
      if (ids.length>0) {
        this.updateIsDelete(ids);
      }else {
        this.$message({
          title:'操作失败',
          message:"未选中客户",
        });
      }
    },
    /**
     * 恢复回收站的客户
     */
    async updateIsDelete(id) {
      const res = await this.$confirm(
          id.length>1?"此操作将会把选中的客户恢复, 是否继续?":"此操作将会把此客户恢复, 是否继续?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
      ).catch(() => {
        this.$message({
          type: "info",
          message: "已取消恢复"
        });
      });
      if (res === "confirm") {
        const { data: res } = await this.$http.put("/resourceInfo/updateIsDelete/" +id);
        console.log(res);
        if(res.success){
          this.$notify.success({
            title:'操作成功',
            message:id.length>1?"选中的客户已成功恢复":"此客户成功恢复",
          });
          await this.getDeleteCustomerList();
        }else {
          this.$message.error(res.data.errorMsg);
        }
      }
    },

    /**
     * 批量分配
     */
    distribute(){
      if (this.multipleSelection.length<1){
        this.$message('未选择资源');
        return;
      }
      this.confirmResourcesId();
    },
    /**
     * 批量分配
     */
    async confirmResourcesId(uIds){
      //展示弹窗
      this.electUsersBoxShow=true
      const createBatchAllocationMap = (uIds) => ({
        userIds: uIds,
      });
      this.batchAllocationMap = createBatchAllocationMap(uIds);
      //获取选中的资源id
      // 当用户确认分配时，发送请求
      if (uIds.length>0) {
        if (this.multipleSelection.map(row => row.resourceId).length>0){
          console.log("$$$$$$$$$$$")
          console.log(this.multipleSelection.map(row => row.resourceId))
          this.id=this.multipleSelection.map(row => row.resourceId);
        }
        const {data: res} = await this.$http.post("/resourceInfo/distributeCustomer/"+this.id , uIds)
        if (res.success) {
          this.$notify.success({
            title: '操作成功',
            message: this.id.length > 1 ? "选中的客户已成功分配" : "此客户成功分配",
          });
          await this.getDeleteCustomerList();
        } else {
          this.$message.error(res.data.errorMsg);
        }
      }
    },

    /**
     * 批量分配
     */
    distribute2(id){
      this.id=id;
      this.confirmResourcesId();
    },

    searchDeleteZiYuanList(){
      this.queryMap_recycle.pageNum = 1;
      this.getDeleteZiYuanList();
    },

    /**
     * 加载进入回收站的资源列表
     */
    async getDeleteZiYuanList() {
      const { data: res } = await this.$http.get("/resourceInfo/IsDeleteFindList", {
        params: this.queryMap_recycle
      });
      if(!res.success){
        return this.$message.error("获取进入回收站的资源列表失败:"+res.data.errorMsg);
      }
      this.totalZiYuanList = res.data.total;
      this.deleteZiYuanList = res.data.rows;
      this.multipleSelection=[]
    },

    /**
     * 批量恢复
     */
    updateIsDeleteZiYuanListList(){
      const ids = this.multipleSelection.map(row => row.resourceId);
      if (ids.length>0) {
        this.updateIsDeleteZiYuanList(ids);
      }else {
        this.$message({
          title:'操作失败',
          message:"未选中资源",
        });
      }
    },
    /**
     * 恢复回收站的资源
     */
    async updateIsDeleteZiYuanList(id) {
      const res = await this.$confirm(
          id.length>1?"此操作将会把选中的资源恢复, 是否继续?":"此操作将会把此资源恢复, 是否继续?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
      ).catch(() => {
        this.$message({
          type: "info",
          message: "已取消恢复"
        });
      });
      if (res === "confirm") {
        const { data: res } = await this.$http.put("/resourceInfo/updateIsDelete/" +id);
        console.log(res);
        if(res.success){
          this.$notify.success({
            title:'操作成功',
            message:id.length>1?"选中的客户已资源恢复":"此客户资源恢复",
          });
          await this.getDeleteZiYuanList();
        }else {
          this.$message.error(res.data.errorMsg);
        }
      }
    },
    /**
     * 根据条件清空进入回收站的资源
     */
    async resourceInfoDeletes(){
      if (this.totalZiYuanList>0){
        const res = await this.$confirm(
            "此操作将会把查询出所有进入回收站的资源删除, 是否继续?",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }
        ).catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
        if (res === "confirm") {
          const { data: res } = await this.$http.post("/resourceInfo/deletesByResourceInfoVO",this.queryMap_recycle);
          console.log(res);
          if(res.success){
            this.$notify.success({
              title:'操作成功',
              message:"查询出所有的信息已成功删除",
            });
            await this.getDeleteZiYuanList();
          }else {
            this.$message.error(res.data.errorMsg);
          }
        }
      }else {
        this.$message({
          title:'操作失败',
          message:"没有任何数据可清空",
        });
      }
    },
    /**
     * 导出回收站的资源
     */
    resourceInfoExcel() {
      const $this = this;
      const res =   axios.post(
          'http://47.99.186.44:8989/resourceInfo/resourceInfoExcel',
          this.queryMap_recycle, // 这里需要注意，queryMap 如果是用于请求体，就直接作为第二个参数传入
          {
            responseType: 'blob',
            headers: {
              'Authorization': LocalStorage.get(LOCAL_KEY_XINGUAN_ACCESS_TOKEN)
            }
          }
      )
          .then(res => {
            if (res.headers["content-type"] === "application/json") {
              return $this.$message.error(
                  "Subject does not have permission [class:export]"
              );
            }
            const data = res.data;
            let url = window.URL.createObjectURL(data); // 将二进制文件转化为可访问的url
            const a = document.createElement("a");
            document.body.appendChild(a);
            a.href = url;
            a.download = "回收站的资源列表.xls";
            a.click();
            window.URL.revokeObjectURL(url);
          });
    },



    /**
     * 获得归属人信息
     */
    async getUserName() {
      const {data: res} = await this.$http.post("/system/departmentUtils/getUserListByMap/", {});
      if (!res.success) {
        return this.$message.error("获取归属人信息失败:" + res.data.errorMsg);
      }
      this.userList = res.data
    },
    /**
     * 获得归属人信息
     */
    async getUserName1() {
      // const {data: res} = await this.$http.post("/system/departmentUtils/getUserListByMap/",this.queryMap_high.accountName);
      // if (!res.success) {
      //   return this.$message.error("获取归属人信息失败:" + res.data.errorMsg);
      // }
      // this.userList = res.data

      this.queryMap_high.industryId="";
      this.queryMap_high.clientTypeId="";
      this.queryMap_high.sourceId="";
      this.queryMap_high.labelId="";
      await this.getClientType1();
      await this.getSource1();
      await this.getIndustry1();
      await this.getLabelInfo();
    },
    /**
     * 获得归属人信息
     */
    async getUserName2() {
      this.queryMap_recycle.industryId="";
      this.queryMap_recycle.userId="";
      const {data: res} = await this.$http.post("/system/departmentUtils/getUserListByMap/",this.queryMap_recycle);
      if (!res.success) {
        return this.$message.error("获取归属人信息失败:" + res.data.errorMsg);
      }
      this.userList = res.data
      // await this.getClientType2();
      // await this.getSource2();
      await this.getIndustry2();
    },
    /**
     * 获得客户状态信息
     */
    /*async getClientStatus(){
      const { data: res } = await this.$http.get("/system/clientStatus/findList");
      if(!res.success){
        return this.$message.error("获取归属人信息失败:"+res.data.errorMsg);
      }
      this.clientStatusList=res.data
    },*/
    /**
    * 获得标签信息
     */
    async getLabelInfo(){
      const {data: res} = await this.$http.get("/system/labelInfo/findList",{params:this.queryMap_high});
      if (!res.success) {
        return this.$message.error("获取标签失败:" + res.data.errorMsg);
      }
      this.labelInfoList = res.data
    },

    async getClientType() {
      const {data: res} = await this.$http.get("/system/clientType/findList");
      if (!res.success) {
        return this.$message.error("获得客户类型信息失败:" + res.data.errorMsg);
      }
      this.clientTypeList = res.data
    },
    /**
     * 获得客户类型信息
     */
    async getClientType1() {
      const {data: res} = await this.$http.get("/system/clientType/findList",{params:this.queryMap_high});
      if (!res.success) {
        return this.$message.error("获得客户类型信息失败:" + res.data.errorMsg);
      }
      this.clientTypeList = res.data
    },
    /**
     * 获得客户类型信息
     */
    async getClientType2() {
      const {data: res} = await this.$http.get("/system/clientType/findList",{params:this.queryMap_recycle});
      if (!res.success) {
        return this.$message.error("获得客户类型信息失败:" + res.data.errorMsg);
      }
      this.clientTypeList = res.data
    },
    /**
     * 获得来源信息
     */
    async getSource() {
      const {data: res} = await this.$http.get("/system/source/findList");
      if (!res.success) {
        return this.$message.error("获得来源信息失败:" + res.data.errorMsg);
      }
      this.sourceList = res.data
    },
    /**
     * 获得来源信息
     */
    async getSource1() {
      const {data: res} = await this.$http.get("/system/source/findList",{params:this.queryMap_high});
      if (!res.success) {
        return this.$message.error("获得来源信息失败:" + res.data.errorMsg);
      }
      this.sourceList = res.data
    },
    /**
     * 获得来源信息
     */
    async getSource2() {
      const {data: res} = await this.$http.get("/system/source/findList",{params:this.queryMap_recycle});
      if (!res.success) {
        return this.$message.error("获得来源信息失败:" + res.data.errorMsg);
      }
      this.sourceList = res.data
    },
    /**
     * 获得行业类型信息
     */
    async getIndustry() {
      const {data: res} = await this.$http.get("/system/industry/findList");
      if (!res.success) {
        return this.$message.error("获得行业类型信息失败:" + res.data.errorMsg);
      }
      this.industryList = res.data
    },
    /**
     * 获得行业类型信息
     */
    async getIndustry1() {
      const {data: res} = await this.$http.get("/system/industry/findList",{params:this.queryMap_high});
      if (!res.success) {
        return this.$message.error("获得行业类型信息失败:" + res.data.errorMsg);
      }
      this.industryList = res.data
    },
    /**
     * 获得行业类型信息
     */
    async getIndustry2() {
      const {data: res} = await this.$http.get("/system/industry/findList",{params:this.queryMap_recycle});
      if (!res.success) {
        return this.$message.error("获得行业类型信息失败:" + res.data.errorMsg);
      }
      this.industryList = res.data
    },
    /**
     * 显示是否呼叫
     */
    showCall(row) {
      let call='';
      if(row.isCall==0){
        call = '未呼叫';
      }else if(row.isCall==1) {
        call = '已呼叫';
      }else{
        call = '未呼叫';
      }
      return call;
    },
    /**
     * 显示资源标签
     */
    showTag(row) {
      let tag='';
      switch (row.resourceTag) {
        case '0':
          tag = '未标记';
          break;
        case '1':
          tag = '无效';
          break;
        case '2':
          tag = '待定';
          break;
        case '3':
          tag = '有效';
          break;
        default:
          tag = '未标记'
      }
      return tag;
    },
    /**
     * 显示是否存在
     */
    showExists(row){
      let value='';
      if(row.isExists==0){
        value = '不存在';
      }else if(row.isExists==1) {
        value = '已存在';
      }else{
        value = '不存在';
      }
      return value;
    },
    /**
     * 当时间选择时，直接赋值
     * @change="handleDateChange" 将其添加到时间中
     */
    handleDateChange() {
      if (this.activeIndex==1){
        this.queryMap_recycle.startTime = this.formatDate(this.time[0], false);
        this.queryMap_recycle.endTime = this.formatDate(this.time[1], true);
      }else {
        this.queryMap_high.startTime = this.formatDate(this.time[0], false);
        this.queryMap_high.endTime = this.formatDate(this.time[1], true);
      }

    },
    // 定义一个格式化时间的函数
    formatDate(date, is) {
      //判断时间是否为空
      if (date != null) {
        //判断是否为结束时间
        if (is) {
          date.setDate(date.getDate() + 1);
        }
        const year = date.getFullYear();
        //+1，是因为月份是从0开始
        const month = ('0' + (date.getMonth() + 1)).slice(-2);
        const day = ('0' + date.getDate()).slice(-2);
        // console.log('格式化前各部分值: 年:', year,'月:', month,'日:', day);
        const hours = ('0' + date.getHours()).slice(-2);
        const minutes = ('0' + date.getMinutes()).slice(-2);
        const seconds = ('0' + date.getSeconds()).slice(-2);
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        // console.log('最终返回结果:', result);
      }
      return null;
    }, /**
     * 获得账号信息
     */
    async getAccountNameList() {
      const {data: res} = await this.$http.get("/system/user/qt/findRoleList");
      if (!res.success) {
        return this.$message.error("获取角色信息失败:" + res.data.errorMsg);
      }
      this.accountName = res.data

    },
  },
  created() {
    this.getAccountNameList();
    // this.getUserName();
    //this.getClientStatus();
    this.getClientType();
    this.getSource();
    this.getIndustry();
    this.getDeleteCustomerList();
    this.getLabelInfo();
  },
  components: {
    ElectUsersBox
  }
};
</script>
<style scoped>

</style>
